<?php
/*
 * Descripción: Carga toda la informacion de los distractores
 */
    //Variables del jqgrid
    $page = $_GET['page']; // get the requested page
    $limit = $_GET['rows']; // get how many rows we want to have into the grid
    $sidx = $_GET['sidx']; // get index row - i.e. user click to sort
    $sord = $_GET['sord']; // get the direction
    if(!$sidx) $sidx =1;
    
    if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
        header("Content-type: application/xhtml+xml;charset=utf-8");
    } else {
        header("Content-type: text/xml;charset=utf-8");
    }
    $et = ">";
    echo "<?xml version='1.0' encoding='utf-8'?$et\n";
    echo "<rows>";

    require_once '../funciones/funciones.php';   //Se hace la inclusion para que no genere conflictos con el XML
    $con = new MySQL();
    //tempInt1 = transaccion
    //tempInt2 = Orden
    //tempInt3 = Clave
    //tempVarchar1 = Descripcion
    $sql = "select COUNT(transaccion) as count from temporal where transaccion = '{$_REQUEST['tran']}'";
    $result = $con->consulta($sql);
    $row = mysql_fetch_array($result,MYSQL_ASSOC);
    $count = $row['count'];

    if( $count >0 ) {
        $total_pages = ceil($count/$limit);
    } else {
        $total_pages = 0;
    }
    if ($page > $total_pages) $page=$total_pages;
    $start = $limit*$page - $limit; // do not put $limit*($page - 1)

    $sql = "select tempId,tempInt2,tempInt3,tempText1 from temporal where transaccion = '{$_REQUEST['tran']}' ORDER BY $sidx $sord LIMIT $start , $limit";
    $result = $con->consulta($sql);
    
    echo "<page>".$page."</page>";
    echo "<total>".$total_pages."</total>";
    echo "<records>".$count."</records>"; // be sure to put text data in CDATA$sql
    //Consulta cantidad
    while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
        $tmp = ($row['tempInt3'] == '1')?"Si":"No";
        echo "<row id='".$row['tempId']."'>";
        echo "<cell>".$row['tempInt2']."</cell>";
        echo "<cell>".$tmp."</cell>";
        echo "<cell>".htmlspecialchars($row['tempText1'])."</cell>";
        echo "</row>";
    }
    echo "</rows>";
?>
